<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button @click="isShow=!isShow">{{isShow?'隐藏':'显示'}}</button>
    <keep-alive>
      <common-head v-if="isShow"></common-head>
    </keep-alive>
  </div>
  <script src="./vue.js"></script>
  <script>
  
    const CommonHead = {
      template: `
        <div>
          <h1>我是公共头部</h1>  
          <input v-model="msg"/>
        </div>
        
      `,
      data(){
        return {
          msg: '字符串'
        }
      },
      mounted () {
        console.log('真实dom编译完成-mounted');;
      },
      activated(){
        console.log('被缓存的组件 再一次显示时触发');
      },
      deactivated(){
        console.log('被缓存组件停用时触发');
      },
      beforeDestroy () {
        console.log('组件卸载之前');;
      }
    };
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      }
    })
  </script>
</body>
</html>